﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.XPath;

namespace ASP.NET_WebForms_Project__kupon_aggregator_.ForAdmins
{
    public partial class ControlPanel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// Загружает данные из XML файлов
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            //Parser.TransferXMLtoDB("../Resources/example.xml");
            XmlReader _xmlReader = XmlReader.Create("http://kuponator.ru/example.xml");
            XPathDocument doc = new XPathDocument("http://kuponator.ru/example.xml");
            XPathNavigator nav = ((IXPathNavigable) doc).CreateNavigator();
            XPathNodeIterator iter = nav.Select("/discounts/offers/offer");           
            while (iter.MoveNext())
            {
                XPathNodeIterator newIterator = iter.Current.SelectDescendants(XPathNodeType.Element, false);
                while (newIterator.MoveNext())
                {
                    Label1.Text += newIterator.Current.Name + " : " + newIterator.Current.Value + "______________________";
                    XPathNodeIterator supplierIter = newIterator.Current.SelectDescendants(XPathNodeType.Element, false);
                    if (supplierIter.Count>1) // данные о supplier
                    {
                        while (supplierIter.MoveNext())
                        {
                            Label1.Text += supplierIter.Current.Name + " : " + supplierIter.Current.Value + "______________________";
                            if (supplierIter.Current.Name == "name")
                            {
                                XPathNodeIterator AdresIter =
                                    supplierIter.Current.SelectDescendants(XPathNodeType.Element, false);
                                XPathNodeIterator NameIter =
                                    AdresIter.Current.SelectDescendants(XPathNodeType.Element, false);
                                Label1.Text += NameIter.Current.Name + " : " + NameIter.Current.Value;
                            }
                        }
                    }
                }

            }          
        }
    }
}